<template>
    <div class="resourcesBox" ref="resourceRef">
        <div class="search">
            <el-input placeholder="请输入关键词" v-model="input3" class="input-with-select">
                <el-button slot="append" icon="el-icon-search" @click="resourcePage">搜索</el-button>
            </el-input>
        </div>
        <div class="uploadResources" v-if="isSupervise">
            <el-button type="warning" size="mini" @click="resoucesEditOrAdd('open')">上传资源</el-button>
        </div>
        <!-- 筛选条件 -->
        <ul class="typeWarp">
            <li class="typelist">
                <label class="typeName">阶段</label>
                <span>：</span>
                <el-radio-group size="mini" class="radioRroup" v-model="radioGroup.stage" @change="handleStageChange">
                    <el-radio-button class="elRadio" :label="item.id" v-for="(item, index) in resourceLearnP"
                        :key="index">{{item.name}}</el-radio-button>
                </el-radio-group>
            </li>
            <li class="typelist">
                <label class="typeName">一级分类</label>
                <span>：</span>
                <el-radio-group size="mini" class="radioRroup" v-model="radioGroup.oneType"
                    @change="handleOneTypeChange">
                    <el-radio-button class="elRadio" :label="item.id" v-for="(item, index) in resourceType1P"
                        :key="index">{{item.name}}</el-radio-button>
                </el-radio-group>
            </li>
            <!--当一级分类等于校本资源时才显示-->
            <!-- <li class="typelist" v-if="radioGroup.oneType == 6"> -->
            <li class="typelist" v-if="radioGroup.oneType !== 5">
                <label class="typeName">二级分类</label>
                <span>：</span>
                <el-radio-group size="mini" class="radioRroup" v-model="radioGroup.twoType">
                    <el-radio-button class="elRadio" :label="item.id" v-for="(item, index) in resourceType2P"
                        :key="index">{{item.name}}</el-radio-button>
                </el-radio-group>
            </li>
            <li class="typelist">
                <label class="typeName">学科</label>
                <span>：</span>
                <el-radio-group size="mini" class="radioRroup" v-model="radioGroup.subject">
                    <el-radio-button class="elRadio" :label="item.id" v-for="(item, index) in resourceSubjectP"
                        :key="index">{{item.name}}</el-radio-button>
                </el-radio-group>
            </li>
            <li class="typelist">
                <label class="typeName">版本</label>
                <span>：</span>
                <el-radio-group size="mini" class="radioRroup" v-model="radioGroup.edition">
                    <el-radio-button class="elRadio" :label="item.id" v-for="(item, index) in resourceVersionP"
                        :key="index">{{item.name}}</el-radio-button>
                </el-radio-group>
            </li>
            <!--当一级分类等于校本资源时才显示-->
            <li class="typelist" v-if="radioGroup.oneType == 3">
                <label class="typeName">分类</label>
                <span>：</span>
                <el-radio-group size="mini" class="radioRroup" v-model="radioGroup.classify">
                    <el-radio-button class="elRadio" :label="item.id" v-for="(item, index) in resourceLearnP"
                        :key="index">{{item.name}}</el-radio-button>
                </el-radio-group>
            </li>
            <!--当一级分类等于升学专题时才显示-->
            <li class="typelist" v-if="radioGroup.oneType == 3">
                <label class="typeName">年份</label>
                <span>：</span>
                <el-radio-group size="mini" class="radioRroup" v-model="radioGroup.year">
                    <el-radio-button class="elRadio" :label="item.id" v-for="(item, index) in resourceListYearP"
                        :key="index">{{item.name}}</el-radio-button>
                </el-radio-group>
            </li>
            <!--当一级分类等于升学专题时才显示-->
            <!-- <li class="typelist" v-if="radioGroup.oneType == 3">
                <label class="typeName">省份</label>
                <span>：</span>
                <el-select size="mini" v-model="regionalLinkage.province" placeholder="请选择省" @change="provinceChange"
                    style="margin-left:10px;">
                    <el-option v-for="item in resourceProvinceP" :key="item.id" :label="item.name" :value="item.id">
                    </el-option>
                </el-select>
                <el-select size="mini" v-model="regionalLinkage.city" placeholder="请选择市" @change="cityChange"
                    style="margin-left:10px;">
                    <el-option v-for="item in resourceListCityP" :key="item.id" :label="item.name" :value="item.id">
                    </el-option>
                </el-select>
                <el-select size="mini" v-model="regionalLinkage.county" placeholder="请选择区" @change="countyChange"
                    style="margin-left:10px;">
                    <el-option v-for="item in resourceListCountyP" :key="item.id" :label="item.name" :value="item.id">
                    </el-option>
                </el-select>
            </li> -->
            <!--当一级分类不等于升学专题时才显示-->
            <li class="typelist" v-if="radioGroup.oneType != 3">
                <label class="typeName">册别</label>
                <span>：</span>
                <el-radio-group size="mini" class="radioRroup" v-model="radioGroup.bookType">
                    <el-radio-button class="elRadio" :label="item.id" v-for="(item, index) in resourceGradeP"
                        :key="index">{{item.name}}</el-radio-button>
                </el-radio-group>
            </li>
            <!--当一级分类等于备课资源、专题资源时才显示-->
            <!-- <li class="typelist" v-if="radioGroup.oneType == 1 || radioGroup.oneType == 4">
                <label class="typeName">二级分类</label>
                <span>：</span>
                <el-radio-group size="mini" class="radioRroup" v-model="radioGroup.twoType">
                    <el-radio-button class="elRadio" :label="item.id" v-for="(item, index) in resourceType2P" :key="index">{{item.name}}</el-radio-button>
                </el-radio-group>
            </li> -->
            <!--当一级分类等于校本资源时才显示-->
            <!-- <li class="typelist" v-if="radioGroup.oneType == 6">
                <label class="typeName">三级分类</label>
                <span>：</span>
                <el-radio-group size="mini" class="radioRroup" v-model="radioGroup.threeType"
                    style="width:calc(100% - 80px);vertical-align: top;">
                    <el-radio-button class="elRadio" :label="item.id" v-for="(item, index) in resourceLearnP" :key="index">{{item.name}}</el-radio-button>
                    <el-radio-button class="elRadio" label="0">全部</el-radio-button>
                    <el-radio-button class="elRadio" label="1">教案</el-radio-button>
                    <el-radio-button class="elRadio" label="2">课件</el-radio-button>
                    <el-radio-button class="elRadio" label="3">学案</el-radio-button>
                    <el-radio-button class="elRadio" label="4">素材</el-radio-button>
                    <el-radio-button class="elRadio" label="5">课程复习</el-radio-button>
                    <el-radio-button class="elRadio" label="6">教学计划</el-radio-button>
                    <el-radio-button class="elRadio" label="7">教学总结</el-radio-button>
                </el-radio-group>
            </li> -->
        </ul>
        <!-- 资源列表 -->
        <ul class="resourcesList">
            <li class="resources">
                <el-checkbox v-if="isShow" :indeterminate="isIndeterminate" v-model="checkAll"
                    @change="handleCheckAllChange">全选</el-checkbox>&nbsp;&nbsp;
                <el-button v-if="isShow" type="text" @click="resoucesEditOrAdd('delBatch',item)">删除</el-button>
            </li>
            <el-checkbox-group v-model="check" @change="handleCheckChange">
                <li class="resources" v-for="(item, index) in resourceList.list" :key="index">
                    <div class="resourcesName">
                        <el-checkbox class="check" v-if="isShow" :label="item.id">{{null}}</el-checkbox>
                        <span class="officeType offPPT">{{item.ext}}</span>
                        <span class="resourcesType">{{item.typeId2?typeIdToName(item.typeId2):''}}</span>
                        <label class="name">{{item.name}}</label>
                    </div>
                    <div class="time">
                        <label class="uploadTime">{{item.creationtime}}</label>
                        <label class="downloadCount">下载次数:{{item.downloadnum}}</label>
                    </div>
                    <div class="operation">
                        <el-button plain size="mini" @click="downloadResource(item)">
                            资源下载
                        </el-button>
                        <el-button type="primary" plain size="mini"
                            v-if="isSupervise && (userId == item.userId || userInfo.id == item.userId)"
                            @click="resoucesEditOrAdd('edit',item)">编辑</el-button>
                        <el-button v-if="isSupervise && (userId == item.userId || userInfo.id == item.userId)"
                            type="danger" plain size="mini" @click="resoucesEditOrAdd('del',item)">删 除</el-button>
                    </div>
                </li>
            </el-checkbox-group>
        </ul>
        <!-- <el-tabs v-model="activeName">
            <el-tab-pane label="全部资源" name="first">全部资源</el-tab-pane>
            <el-tab-pane label="教案" name="second">
                <div class="menuList">
                    <label>同步练习</label>
                    <label>模拟卷</label>
                    <label>真题卷</label>
                    <label>单元测试</label>
                </div>

                <div class="resourcesList">
                    <div class="list">
                        <div class="seebtn">预览</div>
                        <div class="downbtn">下载</div>
                        <div class="listTop">
                            <label class="type">W</label>
                            <span class="typeClass">同步练习</span>
                            <span class="title">湖南二小语文二课时教案</span>
                        </div>
                        <div class="listBtm">
                            <label>
                                上传:2018-08-01 18:22
                            </label>
                            <label>
                                类型:教案
                            </label>
                            <label>
                                上传者:管理员
                            </label>
                        </div>
                    </div>
                    <div class="list">
                        <div class="seebtn">预览</div>
                        <div class="downbtn">下载</div>
                        <div class="listTop">
                            <label class="type">W</label>
                            <span class="typeClass">同步练习</span>
                            <span class="title">湖南二小语文二课时教案</span>
                        </div>
                        <div class="listBtm">
                            <label>
                                上传:2018-08-01 18:22
                            </label>
                            <label>
                                类型:教案
                            </label>
                            <label>
                                上传者:管理员
                            </label>
                        </div>
                    </div>
                    <div class="list">
                        <div class="seebtn">预览</div>
                        <div class="downbtn">下载</div>
                        <div class="listTop">
                            <label class="type">W</label>
                            <span class="typeClass">同步练习</span>
                            <span class="title">湖南二小语文二课时教案</span>
                        </div>
                        <div class="listBtm">
                            <label>
                                上传:2018-08-01 18:22
                            </label>
                            <label>
                                类型:教案
                            </label>
                            <label>
                                上传者:管理员
                            </label>
                        </div>
                    </div>
                    <div class="list">
                        <div class="seebtn">预览</div>
                        <div class="downbtn">下载</div>
                        <div class="listTop">
                            <label class="type">W</label>
                            <span class="typeClass">同步练习</span>
                            <span class="title">湖南二小语文二课时教案</span>
                        </div>
                        <div class="listBtm">
                            <label>
                                上传:2018-08-01 18:22
                            </label>
                            <label>
                                类型:教案
                            </label>
                            <label>
                                上传者:管理员
                            </label>
                        </div>
                    </div>
                </div>
            </el-tab-pane>
            <el-tab-pane label="学案" name="third">学案</el-tab-pane>
            <el-tab-pane label="课件" name="fourth">课件</el-tab-pane>
            <el-tab-pane label="说课稿" name="five">说课稿</el-tab-pane>
            <el-tab-pane label="试卷试题" name="six">试卷试题</el-tab-pane>
            <el-tab-pane label="课程复习" name="seven">课程复习</el-tab-pane>
            <el-tab-pane label="教学计划" name="eight">教学计划</el-tab-pane>
            <el-tab-pane label="教学总结" name="nine">教学总结</el-tab-pane>
        </el-tabs> -->
        <!-- 上传弹框 -->
        <el-dialog :title="title" center :visible.sync="isEditOrAdd" width="45%">
            <el-form :model="dialogForm" label-width="95px" :rules="rules" ref="ruleForm">
                <el-form-item label="阶段：" prop="stage">
                    <el-select size="mini" v-model="dialogForm.stage" @change="handleStageChange" placeholder="请选择阶段">
                        <el-option :label="item.name" :value="item.id" v-for="(item, index) in resourceLearnP"
                            :key="index"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="一级分类：" prop="oneType">
                    <el-radio-group size="mini" v-model="dialogForm.oneType" @change="handleOneTypeChange">
                        <el-radio :label="item.id" v-for="(item, index) in resourceType1P" :key="index">{{item.name}}
                        </el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="二级分类：" v-if="dialogForm.oneType !== 3" prop="twoType">
                    <el-radio-group size="mini" v-model="dialogForm.twoType">
                        <el-radio :label="item.id" v-for="(item, index) in resourceType2P" :key="index">{{item.name}}
                        </el-radio>
                    </el-radio-group>
                </el-form-item>
                <!--当一级分类等于升学专题时才显示-->
                <!-- <el-form-item label="省份：" v-if="dialogForm.oneType == 3" prop="province">
                    <el-select size="mini" v-model="dialogForm.province" placeholder="请选择省份" @change="provinceChangeF">
                        <el-option v-for="item in resourceProvinceP" :key="item.id" :label="item.name" :value="item.id">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="市区：" v-if="dialogForm.oneType == 3" prop="city">
                    <el-select size="mini" v-model="dialogForm.city" placeholder="请选择市区" @change="cityChangeF">
                        <el-option v-for="item in resourceListCityP" :key="item.id" :label="item.name" :value="item.id">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="县级：" v-if="dialogForm.oneType == 3" prop="county">
                    <el-select size="mini" v-model="dialogForm.county" placeholder="请选择县级" @change="countyChangeF">
                        <el-option v-for="item in resourceListCountyP" :key="item.id" :label="item.name"
                            :value="item.id">
                        </el-option>
                    </el-select>
                </el-form-item> -->
                <el-form-item label="学科：" prop="subject">
                    <el-select size="mini" v-model="dialogForm.subject" placeholder="请选择学科">
                        <el-option :label="item.name" :value="item.id" v-for="(item, index) in resourceSubjectP"
                            :key="index"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="版本：" prop="edition">
                    <el-select size="mini" v-model="dialogForm.edition" placeholder="请选择版本">
                        <el-option :label="item.name" :value="item.id" v-for="(item, index) in resourceVersionP"
                            :key="index"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="册别：" prop="bookType">
                    <el-select size="mini" v-model="dialogForm.bookType" placeholder="请选择版本">
                        <el-option :label="item.name" :value="item.id" v-for="(item, index) in resourceGradeP"
                            :key="index"></el-option>
                    </el-select>
                </el-form-item>
                <!-- <el-form-item label="二级分类：" v-if="dialogForm.oneType < 4">
                    <el-select size="mini" v-model="dialogForm.twoTypeCopy" placeholder="请选择版本">
                        <el-option label="专题讲座" value="0"></el-option>
                        <el-option label="专项训练" value="1"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="三级分类：" v-if="dialogForm.oneType == 5">
                    <el-select size="mini" v-model="dialogForm.threeType" placeholder="请选择版本">
                        <el-option label="教案" value="0"></el-option>
                        <el-option label="课件" value="1"></el-option>
                        <el-option label="学案" value="2"></el-option>
                    </el-select>
                </el-form-item> -->
                <el-form-item label="资源文件：">
                    <el-upload class="upload-demo" :action="'' | baseUpPUrl" :on-preview="handlePreview"
                        :on-remove="handleRemove" :before-remove="beforeRemove" multiple :limit="1"
                        :on-exceed="handleExceed" :file-list="fileList" :on-success="upSuccess"
                        :on-change="resourceChange">
                        <el-button size="small" type="primary">点击上传</el-button>
                    </el-upload>
                </el-form-item>
                <el-form-item label="资源名称：" prop="name">
                    <el-input size="mini" v-model="dialogForm.name" style="width: 193px;"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer" style="text-align: end;">
                <el-button size="mini" @click="isEditOrAdd = false">取 消</el-button>
                <el-button size="mini" type="primary" @click="resourcePost">确 定</el-button>
            </div>
        </el-dialog>
        <!--分页-->
        <div class="block">
            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                :current-page.sync="currentPage" :page-size="pageSize" :page-sizes="[10, 20, 30, 50]"
                layout="total, sizes, prev, pager, next, jumper" :total="totals">
            </el-pagination>
        </div>
    </div>
</template>

<script>
    import {
        pictureUrl
    } from '@/utils/filter'
    import {
        mapState
    } from "vuex";
    export default {
        props: ['isSupervise', 'isShow'],
        computed: {
            ...mapState({
                // 用户详细信息
                userInfo: state => state.userModule.userInfo,
                otherUserInfo: state => state.userModule.otherUserInfo,

            }),
            userId() {
                return this.otherUserInfo.userid || this.userInfo.id
            }
        },
        watch: {
            isEditOrAdd(val) {
                this.resetOptions()
            },
            radioGroup: {
                handler(val) {
                    this.resourcePage()
                },
                deep: true
            }
        },
        created() {
            this.resourceGrade(1) //册别
            this.resourceLearn() //阶段
            this.resourceProvince() //省份
            this.resourceSubject(1) // 科目
            this.resourceType1() //一级分类
            this.resourceType2() //二级分类
            this.resourceVersion() //版本
            this.resourcePage()
            this.resourceListCity('520000')
            this.resourceListCounty('520100')
            this.resourceListYear()
        },
        data() {
            return {
                checkAll: false,
                check: [],
                isIndeterminate: false,
                totals: 0,
                pageSize: 10,
                currentPage: 1,
                radioGroup: {
                    stage: '1', // 阶段
                    oneType: 0, // 一级分类
                    copyOneType: '1',
                    subject: '0', // 学科
                    edition: '0', // 版本
                    bookType: 0, // 册别
                    twoType: 0, // 二级分类
                    threeType: '0', // 三级分类
                    classify: '0', // 分类
                    year: '', // 年份

                },
                fileList: [],
                dialogForm: {
                    stage: 1,
                    oneType: 1,
                    twoType: 1,
                    twoTypeCopy: '',
                    threeType: '',
                    subject: '',
                    edition: '',
                    bookType: '',
                    name: ''
                },
                // 资源
                resourceList: {},
                resourceP: {
                    gradeId: '',
                    learnId: '',
                    limit: 50,
                    page: 1,
                    provinceId: '',
                    search: '',
                    subjectId: '',
                    typeId1: '',
                    typeId2: '',
                    versionId: '',
                    year: ''
                },
                regionalLinkage: {
                    province: 520000,
                    city: 520100,
                    county: 520101
                },
                isEditOrAdd: false,
                activeName: 'second',
                input3: "",
                resourceLearnP: [],
                resourceVersionP: [],
                resourceType2P: [],
                resourceType1P: [],
                resourceSubjectP: [],
                resourceProvinceP: [],
                resourceListCityP: [],
                resourceListCountyP: [],
                resourceGradeP: [],
                resourceListYearP: [],
                rules: {
                    name: [{
                            required: true,
                            message: '请输入资源名称',
                            trigger: 'blur'
                        },
                        {
                            min: 2,
                            max: 25,
                            message: '长度在 2 到 25 个字符',
                            trigger: 'blur'
                        }
                    ],
                    stage: [{
                        required: true,
                        message: '请选择阶段',
                        trigger: 'blur'
                    }, ],
                    oneType: [{
                        required: true,
                        message: '请选择一级分类',
                        trigger: 'blur'
                    }, ],
                    twoType: [{
                        required: true,
                        message: '请选择二级分类',
                        trigger: 'blur'
                    }, ],
                    province: [{
                        required: true,
                        message: '请选择省份',
                        trigger: 'blur'
                    }, ],
                    city: [{
                        required: true,
                        message: '请选择市区',
                        trigger: 'blur'
                    }, ],
                    county: [{
                        required: true,
                        message: '请选择县级',
                        trigger: 'blur'
                    }, ],
                    subject: [{
                        required: true,
                        message: '请选择科目',
                        trigger: 'blur'
                    }, ],
                    edition: [{
                        required: true,
                        message: '请选择版本',
                        trigger: 'blur'
                    }, ],
                    bookType: [{
                        required: true,
                        message: '请选择册别',
                        trigger: 'blur'
                    }, ],
                },
                typeName: []
            }
        },
        methods: {
            upSuccess(res) {
                if (res.code == 400) {
                    this.$message.warning("资源上传失败！")
                }
            },
            handleCheckChange(params) {
                if (this.check.length == 0) {
                    this.isIndeterminate = false
                } else if (this.check.length == this.resourceList.list.length) {
                    this.isIndeterminate = false
                    this.checkAll = true
                } else {
                    this.isIndeterminate = true
                    this.checkAll = false
                }
            },
            // 全选框选择时触发
            handleCheckAllChange(params) {
                if (params) {
                    this.checkAll = true
                    this.isIndeterminate = false
                    this.resourceList.list.map(item => {
                        if (item.id) {
                            this.check.push(item.id)
                        }
                    })
                } else {
                    this.check = []
                    this.isIndeterminate = false
                }
            },
            typeIdToName(params) {
                if (this.resourceType2P && this.resourceType2P.filter(item => item.id == params)[0]) {
                    return this.resourceType2P.filter(item => item.id == params)[0].name
                } else {
                    return ''
                }

            },
            resetOptions() {
                this.resourceGrade(this.dialogForm.stage) //册别
                this.resourceLearn() //阶段
                this.resourceProvince() //省份
                this.resourceSubject(this.dialogForm.stage) // 科目
                this.resourceType1() //一级分类
                this.resourceType2() //二级分类
                this.resourceVersion(this.dialogForm.stage) //版本
            },
            countyChange(params) {
                this.dialogForm.county = params
            },
            cityChange(params) {
                this.regionalLinkage.county = null
                this.resourceListCounty(params)
            },
            provinceChange(params) {
                this.regionalLinkage.city = null
                this.regionalLinkage.county = null
                this.resourceListCity(params)
            },
            countyChangeF(params) {
                // console.log(params)
                this.dialogForm.county = params
            },
            cityChangeF(params) {
                // this.dialogForm.county = null
                this.resourceListCounty(params)
            },
            provinceChangeF(params) {
                this.dialogForm.city = null
                this.dialogForm.county = null
                this.resourceListCity(params)
            },
            downloadResource(params) {
                var alink = document.createElement("a");
                alink.target = "_Blank";
                alink.href = pictureUrl(params.path);
                alink.download = params.path; //图片名
                alink.click();
                // window.location.href = pictureUrl(params.path)
                this.resourceDownNum(params)
            },
            resourceChange(file, fileList) {
                this.dialogForm.name = file.name.split('.')[0]
                this.fileList = fileList
            },
            resourcePost() {
                // this.fileList[0].response.result.originalUrl
                // if(!this.fileList[0].response.result.originalUrl){
                //     this.$message.warning("资源上传失败，不能新增资源")
                //     return
                // }
                this.$refs.ruleForm.validate((valid) => {
                    if (valid) {
                        if (this.dialogForm.id) {
                            this.resourcePut()
                        } else {
                            if (this.fileList[0]) {
                                this.$store.dispatch('resourceModule/resourcePost', {
                                    gradeId: this.dialogForm.bookType,
                                    id: null,
                                    learnId: this.dialogForm.stage,
                                    name: this.dialogForm.name,
                                    path: this.fileList[0].response.result.originalUrl,
                                    provinceId: null,
                                    subjectId: this.dialogForm.subject,
                                    typeId1: this.dialogForm.oneType,
                                    typeId2: this.dialogForm.twoType,
                                    typeId3: null,
                                    versionId: this.dialogForm.edition,
                                }).then(res => {
                                    if (res) {
                                        this.resourcePage()
                                        this.$message.success('上传成功')
                                        this.fileList = []
                                        this.isEditOrAdd = false
                                    }
                                })
                            } else {
                                this.$message.warning('请先上传文件')
                            }
                        }
                    } else {
                        // console.log('error submit!!');
                        return false;
                    }
                });
            },
            resourcePut() {
                this.$store.dispatch('resourceModule/resourcePut', {
                    gradeId: this.dialogForm.bookType,
                    id: this.dialogForm.id,
                    learnId: this.dialogForm.stage,
                    name: this.dialogForm.name,
                    path: this.fileList[0] ?
                    this.fileList[0].response.result.originalUrl : this.dialogForm.path,
                    provinceId: null,
                    subjectId: this.dialogForm.subject,
                    typeId1: this.dialogForm.oneType,
                    typeId2: this.dialogForm.twoType,
                    typeId3: null,
                    versionId: this.dialogForm.edition
                }).then(res => {
                    if (res) {
                        this.$message.success('编辑成功')
                        this.fileList = []
                        this.isEditOrAdd = false
                        this.resourcePage()
                    }
                })
            },
            resourceDel(params) {
                this.$confirm('确定删除所选的数据吗？', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.$store.dispatch('resourceModule/resourceDel', {
                        ids: params.id
                    }).then(res => {
                        if (res) {
                            this.$message.success('删除成功')
                            this.resourcePage()
                        }
                    })
                }).catch(() => {
                    this.$message.info('已点击取消')
                });
            },
            resourceDownNum(params) {
                this.$store.dispatch('resourceModule/resourceDownNum', {
                    id: params.id
                }).then(res => {
                    if (res) {
                        this.resourcePage()
                    }
                })
            },
            resourceListCity(params) {
                this.$store.dispatch('resourceModule/resourceListCity', {
                    isHideAllOption: false,
                    id: params,
                }).then(res => {
                    if (res) {
                        this.resourceListCityP = res
                    }
                })
            },
            resourceListCounty(params) {
                this.$store.dispatch('resourceModule/resourceListCounty', {
                    isHideAllOption: false,
                    id: params,
                }).then(res => {
                    if (res) {
                        this.resourceListCountyP = res
                    }
                })
            },
            resourceListYear(params) {
                this.$store.dispatch('resourceModule/resourceListYear', {
                    isHideAllOption: this.isEditOrAdd ? false : true,
                }).then(res => {
                    if (res) {
                        this.resourceListYearP = res
                    }
                })
            },
            resourceGrade(params) {
                this.$store.dispatch('resourceModule/resourceGrade', {
                    isHideAllOption: this.isEditOrAdd ? false : true,
                    learnId: params,
                }).then(res => {
                    if (res) {
                        this.resourceGradeP = res
                    }
                })
            },
            resourceLearn() {
                this.$store.dispatch('resourceModule/resourceLearn', {
                    isHideAllOption: false,
                }).then(res => {
                    if (res) {
                        this.resourceLearnP = res
                    }
                })
            },
            resourceProvince() {
                this.$store.dispatch('resourceModule/resourceProvince', {
                    isHideAllOption: false,
                }).then(res => {
                    if (res) {
                        this.resourceProvinceP = res
                    }
                })
            },
            resourceSubject(params) {
                this.$store.dispatch('resourceModule/resourceSubject', {
                    isHideAllOption: this.isEditOrAdd ? false : true,
                    learnId: params,
                }).then(res => {
                    if (res) {
                        this.resourceSubjectP = res
                    }
                })
            },
            resourceType1() {
                this.$store.dispatch('resourceModule/resourceType1', {
                    isHideAllOption: this.isEditOrAdd ? false : true,
                }).then(res => {
                    if (res) {
                        this.resourceType1P = res
                    }
                })
            },
            resourceType2(params) {
                this.$store.dispatch('resourceModule/resourceType2', {
                    isHideAllOption: this.isEditOrAdd ? false : true,
                    learnId: params,
                }).then(res => {
                    if (res) {
                        this.resourceType2P = res
                    }
                })
            },
            resourceVersion(params) {
                this.$store.dispatch('resourceModule/resourceVersion', {
                    isHideAllOption: this.isEditOrAdd ? false : true,
                    learnId: params,
                }).then(res => {
                    if (res) {
                        this.resourceVersionP = res
                    }
                })
            },
            resourcePage() {
                this.resourceP.learnId = this.radioGroup.stage
                this.resourceP.typeId1 = this.radioGroup.oneType
                this.resourceP.typeId2 = this.radioGroup.twoType
                this.resourceP.subjectId = this.radioGroup.subject
                this.resourceP.gradeId = this.radioGroup.bookType
                this.resourceP.versionId = this.radioGroup.edition - 0
                this.resourceP.search = this.input3
                this.resourceP.year = this.radioGroup.year
                this.resourceP.limit = this.pageSize
                this.resourceP.page = this.currentPage
                this.resourceP.isQuerySelf = this.isShow == undefined ? 0 : 1
                // if (this.radioGroup.oneType == 3) {
                //     this.resourceP.provinceId = this.regionalLinkage.province
                // } else {
                //     this.resourceP.provinceId = ''
                // }
                this.$store.dispatch('resourceModule/resourcePage', {
                    ...this.resourceP
                }).then(res => {
                    if (res) {
                        this.totals = res.total
                        this.resourceList = res
                    }
                })
            },
            resoucesEditOrAdd(params, params1) {
                if (params == 'delBatch') {
                    if (this.check.length > 0) {
                        this.resourceDel({
                            id: this.check.join(',')
                        })
                        this.check = []
                        this.isIndeterminate = false
                        this.checkAll = false
                    } else {
                        this.$message.warning('请选择数据!')
                    }
                } else if (params == 'del') {
                    this.resourceDel(params1)
                } else {
                    if (params1) {
                        this.title = '编辑资源'
                        this.dialogForm.stage = Number(params1.learnId)
                        this.dialogForm.bookType = Number(params1.gradeId)
                        this.dialogForm.id = params1.id
                        this.dialogForm.name = params1.name
                        this.dialogForm.path = params1.path
                        this.dialogForm.subject = Number(params1.subjectId)
                        this.dialogForm.twoType = Number(params1.typeId2)
                        this.dialogForm.oneType = Number(params1.typeId1)
                        this.dialogForm.edition = Number(params1.versionId)
                    }else{
                        this.title = '上传资源'
                    }
                    if (params == 'open') {
                        this.dialogForm = {
                            stage: 1,
                            oneType: 1,
                            twoType: 1,
                            twoTypeCopy: '',
                            threeType: '',
                            subject: '',
                            edition: '',
                            bookType: '',
                            name: ''
                        }
                    }
                    this.isEditOrAdd = true
                }
            },
            // 每页显示条数
            handleSizeChange(val) {
                this.pageSize = val
                this.resourcePage()
            },

            // 当前页
            handleCurrentChange(val) {
                this.currentPage = val
                this.resourcePage()
            },

            // 阶段切换
            handleStageChange(val) {
                this.resourceGrade(val)
                this.resourceSubject(val)
            },

            // 一级分类切换
            handleOneTypeChange(val) {
                this.resourceType2(val)
            },

            handleRemove(file, fileList) {
                // console.log(file, fileList);
            },
            handlePreview(file) {
                // console.log(file);
            },
            handleExceed(files, fileList) {
                this.$message.warning(
                    `当前限制选择 1 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`);
            },
            beforeRemove(file, fileList) {
                return this.$confirm(`确定移除 ${file.name}？`);
            }
        }
    }
</script>

<style lang="scss" scoped>
    /deep/.el-radio-button__inner {
        border: none !important;
    }

    .resourcesBox {
        overflow: hidden;
        background: #fff;
        padding: 10px;
        position: relative;
        text-align: center;

        .typeWarp {
            list-style-type: none;
            margin-block-start: 0;
            margin-block-end: 0;
            padding-inline-start: 0;


            .typelist {
                text-align: left;
                margin-top: 20px;

                .typeName {
                    display: inline-block;
                    width: 60px;
                    text-align: justify;
                    text-align-last: justify;
                    font-size: 14px;
                    color: #303133;
                }

                .elRadio>.el-radio-button__inner {
                    margin-left: 10px;
                }

                .elRadio.el-radio-button:first-child>.el-radio-button__inner,
                .elRadio.el-radio-button:last-child>.el-radio-button__inner {
                    border: none;
                    border-radius: 0;
                }

                .radioRroup {
                    width: calc(100% - 80px);
                    vertical-align: top;
                }
            }
        }

        .resourcesList {
            list-style-type: none;
            margin-block-start: 0;
            margin-block-end: 0;
            padding-inline-start: 0;
            box-sizing: border-box;
            padding: 0 20px;
            margin: 30px 0;

            .resources {
                box-sizing: border-box;
                padding-bottom: 10px;
                border-bottom: 1px solid #DCDFE6;
                position: relative;
                text-align: left;
                margin-top: 20px;

                .resourcesName {
                    font-size: 14px;
                    color: #303133;
                    // cursor: pointer;

                    .check {
                        margin-right: 10px;
                    }

                    .officeType {
                        display: inline-block;
                        width: 35px;
                        height: 25px;
                        text-align: center;
                        line-height: 25px;

                    }

                    .offPPT {
                        border: 1px solid orange;
                        color: orange;
                    }

                    .offWORD {
                        border: 1px solid #46A3FF;
                        color: #46A3FF;
                    }

                    .offXLS {
                        border: 1px solid #67C23A;
                        color: #67C23A;
                    }

                    .resourcesType {
                        display: inline-block;
                        box-sizing: border-box;
                        padding: 2px 4px;
                        color: #409EFF;
                        border: 1px solid #409EFF;
                        margin: 0 10px;
                    }

                    label {
                        cursor: pointer;
                    }
                }

                .time {
                    box-sizing: border-box;
                    padding-left: 36px;
                    font-size: 14px;
                    color: #909399;
                    margin-top: 10px;

                    .downloadCount {
                        margin-left: 14px;
                    }
                }

                .operation {
                    position: absolute;
                    top: 10px;
                    right: 0;
                }

            }
        }

        .search {
            width: 290px;
            margin-bottom: 20px;
        }

        .uploadResources {
            position: absolute;
            right: 20px;
            top: 20px;
        }

        .menuList {
            overflow: hidden;
            background: #CCFFFF;
            padding: 5px;

            label {
                display: block;
                float: left;
                margin-right: 15px;

                &:hover {
                    color: #6699CC;
                    cursor: pointer
                }
            }
        }

        .resourcesList {
            overflow: hidden;
            padding: 20px;
            background: #fff;
            margin: 20px auto;

            .list {
                margin-bottom: 10px;
                overflow: hidden;
                font-size: 14px;
                border-bottom: 1px solid #ccc;
                padding-bottom: 10px;
                position: relative;

                .seebtn {
                    position: absolute;
                    right: 20px;
                    top: 10px;
                    border: 1px solid #99CCFF;
                    border-radius: 4px;
                    padding: 3px;

                    &:hover {
                        background: #99CCFF;
                        color: #fff;
                        cursor: pointer;
                    }
                }

                .downbtn {
                    position: absolute;
                    right: 70px;
                    top: 10px;
                    border: 1px solid #99CCFF;
                    border-radius: 4px;
                    padding: 3px;

                    &:hover {
                        background: #99CCFF;
                        color: #fff;
                        cursor: pointer;
                    }
                }

                .listTop {
                    overflow: hidden;

                    .type {
                        display: block;
                        padding: 5px;
                        border: 1px solid #ccc;
                        float: left;
                    }

                    .typeClass {
                        display: block;
                        float: left;
                        padding: 5px;
                        border: 1px solid #99CCFF;
                        border-radius: 4px;
                        margin-left: 10px;
                    }

                    .title {
                        display: block;
                        float: left;
                        margin: 0;
                        height: 35px;
                        line-height: 35px;
                        width: 200px;
                        margin-left: 20px;
                    }
                }

                .listBtm {
                    overflow: hidden;

                    label {
                        display: block;
                        float: left;
                        color: #ccc;
                        margin-right: 40px;
                    }
                }
            }
        }
    }
</style>